package com.boot2523.myrabbitmq.q3;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {
    private static final String EXCHANGE_NAME = "ps_logs";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");

        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {

            // 声明一个 fanout 类型的 exchange，广播模式
            channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

            // 要发送的消息
            String message = "This is a broadcast log message.";

            // 发送消息到 exchange（不指定 routingKey）
            channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes("UTF-8"));
            System.out.println(" [x] Sent '" + message + "'");
        }
    }
}
